/*
 * Gate.cpp
 *
 * Created on: 05-05-2014
 *     Author: A.W. Janisse
 *
 * Version 1.0: 24-05-2014, Final release
 */

#include "Gate.h"
#include <cstdio>
#include <iostream>
#include <sstream>

int Gate::nextNumber = 0;

Gate::Gate(int x, int y, string type)
:x(x), y(y)
{
    nextNumber++;
    this->type = type;
    this->nr = nextNumber;
}

Gate::~Gate()
{
}

int Gate::getX()
{
    return x;
}

int Gate::getY()
{
    return y;
}

int Gate::getNumber()
{
    return nr;
}

string Gate::getType()
{
    return type;
}

void Gate::resetNextNumber()
{
    nextNumber = 0;
}

string Gate::serialize()
{
    stringstream serialString;

    serialString << getType();
    serialString << ",";
    serialString << getX();
    serialString << ",";
    serialString << getY();
    serialString << "\n";

    // Build connection 0 information
    if(getEntry(0) != NULL)
    {
        serialString << "Connection";
        serialString << ",";
        serialString << getEntry(0)->getX();
        serialString << ",";
        serialString << getEntry(0)->getY();
        serialString << ",";
        serialString << getX();
        serialString << ",";
        serialString << getY();
        serialString << "\n";
    }
    // Build connection 1 information
    if(getEntry(1) != NULL)
    {
        serialString << "Connection";
        serialString << ",";
        serialString << getEntry(1)->getX();
        serialString << ",";
        serialString << getEntry(1)->getY();
        serialString << ",";
        serialString << getX();
        serialString << ",";
        serialString << getY();
        serialString << "\n";
    }

    return serialString.str();
}
